package com.jiajia.server.controller;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.jiajia.server.pojo.Employee;
import com.jiajia.server.pojo.RespBean;
import com.jiajia.server.pojo.RespPageBean;
import com.jiajia.server.pojo.Salary;
import com.jiajia.server.service.IEmployeeService;
import com.jiajia.server.service.ISalaryService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ZSJia
 * @date 2021/8/22 022 - 11:28
 */
@RestController
@RequestMapping("/sal/sobcfg")
public class SalarySobCfgController {

    @Autowired
    private ISalaryService salaryService;
    @Autowired
    private IEmployeeService employeeService;

    @ApiOperation(value = "查询所有账套")
    @GetMapping("/salary")
    public List<Salary> findListSalary(){
        return salaryService.list();
    }

    @ApiOperation(value = "更新员工账套")
    @PostMapping("/")
    public RespBean addSalarySobCfg(Integer eid,Integer sid){
        if (employeeService.update(new UpdateWrapper<Employee>().set("salary_id",sid).eq("id",eid))){
            return RespBean.success("更新成功");
        }
        return  RespBean.error("更新失败");
    }

    @ApiOperation(value = "查询员工账套")
    @GetMapping("/")
    public RespPageBean findListSalarySobCfg(@RequestParam(defaultValue = "1") Integer page
                                                                            ,@RequestParam(defaultValue = "10") Integer size){

        return  employeeService.findListSalarySobCfg(page,size);
    }


}
